﻿'use strict';
/**
*Application class 
*auth:lww
*version:1.0
*date:2014-10-11
*/
function Application() {
    window.appInstance = this;
    this.version = "1.0";
    this.name = "Application";
    this.mAppConfig = null;
    this.mRootViewObject = null;
    this.mPageObject = null;
    this.mDialogObject = null;
    this.router = null;
    this.uiIndex = 100;
}
Application.prototype.init = function () {
    /**init app config**/
    this.mAppConfig = new AppConfig(this);      
    document.title = this.mAppConfig.getTitle();   
    /**init rootView **/
    this.mRootViewObject = new FrameLayout(this, this.getLayerIndex());
    this.mRootViewObject.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
    this.mRootViewObject.setBackground(new Drawable(null, DefaultBgImage));
    document.body.appendChild(this.mRootViewObject.view()); 
    /**init router**/
    this.router = new Router(this,this.mAppConfig);      
    /**app init end**/
};
Application.prototype.getLayerIndex = function () {
    return ++this.uiIndex;
};
Application.prototype.setContentView = function (viewObject) {
    if (viewObject != null && typeof (viewObject) == 'object') {
        this.mPageObject = viewObject;
        this.mRootViewObject.removeAllView();
        this.mRootViewObject.addChildView(this.mPageObject.view());
    }
};
Application.prototype.openDialog = function (lpars, isCenter, viewObject, isDrag) {
    if(isNull(viewObject)){
        return null;
    }    
    this.closeDialog();
    if (this.mDialogObject == null) {
        this.mDialogObject = new Dialog(this);
    }
    if (lpars != null) {
        this.mDialogObject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT), isCenter);
    }
    else {
        this.mDialogObject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT), true);
    }
    this.mDialogObject.setContentView(viewObject);
    this.mDialogObject.setDrag(isDrag);
    this.mRootViewObject.addChildView(this.mDialogObject.view());       
    return this.mDialogObject;    
};
Application.prototype.closeDialog = function (arg) {
    if (this.mDialogObject != null) {
        this.mDialogObject.close(arg);
    }
};

markscript("application");
//end application.js